package com.zh.plus;

import com.zh.entity.User;
import com.zh.util.UserContext;
import com.zh.util.dict.CodeMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Service
public class AdminAccessInterceptor extends BaseInterceptor {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = UserContext.getUser();

        if (!"admin".equals(user.getRole())) {
            render(response, CodeMsg.PERMISSION_ERROR);
            return false;
        }

        return true;

    }
}
